import { Component } from 'react'

class Twoc extends Component {
    constructor() {
        super()
        this.state = {}
    }
    del =(id)=>{
        // console.log(this.state.name,this.state.age);
        
        this.props.delc(id)
    }
    edit =(id)=>{
        let list = JSON.parse(JSON.stringify(this.props.list))
        let obj = list.find((e,i)=>e.id === id)
        this.props.edit(obj ,id)
    }
    render() {
        return (
            <table width="400px">
                <thead>
                    <tr >
                        <th>name</th>
                        <th>age</th>
                        <th>del</th>
                    </tr>
                </thead>
                <tbody align="center">
                    {
                        this.props.list.length > 0 ? this.props.list.map((item, index) => {
                            return (
                                <tr key={item.id}>
                                    <td>{item.name}</td>
                                    <td>{item.age}</td>
                                    <td>
                                        <button onClick={() => this.del(item.id)}>del</button>
                                        <button onClick={() => this.edit(item.id)}>edit</button>
                                    </td>

                                </tr>
                            )
                        }) : <tr><th colSpan="3">暂无数据</th></tr>
                    }
                </tbody>
            </table>
        )
    }
}

export default Twoc